package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.*;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IOceanegineService;
import com.ylyq.ylxx.util.Tools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName OceanengineController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/6/24 16:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/oCeanengine/sysuer")
@Api(description = "巨量引擎的用户信息相关接口")
public class OceanengineController {
    @Autowired
    private IOceanegineService iOceanegineService;

    /**
     * @return com.ylyq.ylxx.model.ResponseData
     * @Author xiaweichao
     * @Description //TODO 获取已授权账户信息 * @Date 11:46 2020/6/24
     * @Param []
     **/
    @GetMapping("/getUserInfoByToken")
    @ApiOperation(value = "获取token对应的user信息", response = OceanengineUserInfoByToken.class)
    public ResponseData getUserInfoByToken() {
        return iOceanegineService.getUserInfoByToken();
    }

    @GetMapping("/getUserInfo")
    @ApiOperation(value = "获取已授权账户信息,拿广告主信息", response = OceanengineAccount.class)
    public ResponseData getUserInfo() {
        return iOceanegineService.getUserInfo();
    }

    @PostMapping("/getBalance")
    @ApiOperation(value = "获取账户余额和今日消耗", response = OceanengineGetBalance.class)
    public ResponseData getBalance(@RequestBody GetBalanceRequest getBalanceRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getBalance(getBalanceRequest));
    }

    @PostMapping("/getAccountDay")
    @ApiOperation(value = "获取账户日预算", response = GetAccount.class)
    public ResponseData getAccountDay(@RequestBody GetAccountDayRequest getAccountDayRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getAccountDay(getAccountDayRequest));
    }

    @PostMapping("/updateAccount")
    @ApiOperation(value = "更新账户日预算")
    public ResponseData updateAccount(@RequestBody UpdateAccountRequest updateAccountRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.updateAccount(updateAccountRequest));
    }

    @PostMapping("/getAccount")
    @ApiOperation(value = "获取账户预算", response = YlyqBudgetResponse.class)
    public ResponseData getAccount(@RequestBody GetAccountRequest getAccountRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getAccount(getAccountRequest));
    }

    @PostMapping("/setAccount")
    @ApiOperation(value = "设置账户预算")
    public ResponseData setAccount(@RequestBody SetAccountRequest setAccountRequest) {
        return iOceanegineService.setAccount(setAccountRequest);
//        return new ResponseData(ResponseData.Result.SUCCESS);
    }

    @PostMapping("/isSetAccount")
    @ApiOperation(value = "是否设置了账户预算", response = IsSetAccount.class)
    public ResponseData isSetAccount(@RequestBody IsSetAccountRequest issetAccountRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.isSetAccount(issetAccountRequest));
    }

    @PostMapping("/getManagerData")
    @ApiOperation(value = "获取管家数据", response = GroupReportInfo.class)
    public ResponseData getManagerData(@RequestBody GetManagerDataRequest getBalanceRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getManagerData(getBalanceRequest));
    }

    @PostMapping("/getManagerDataList")
    @ApiOperation(value = "获取管家组数据列表", response = GroupReportInfo.class)
    public ResponseData getManagerDataList(@RequestBody GetManagerDataRequest getBalanceRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getManagerDataList(getBalanceRequest));
    }

    @PostMapping("/getManagerDataListPage")
    @ApiOperation(value = "获取管家组数据列表-分页", response = ManagerDataListPage.class)
    public ResponseData getManagerDataListPage(@RequestBody GetManagerDataRequest getBalanceRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getManagerDataListPage(getBalanceRequest));
    }

    @PostMapping("/getManagerCore")
    @ApiOperation(value = "获取管家评分值", response = ManagerCore.class)
    public ResponseData getManagerCore(@RequestBody GetManagerCoreRequest getManagerCoreRequest) {
        GetManagerDataRequest getBalanceRequest = new GetManagerDataRequest();
        getBalanceRequest.setAdvertiser_id(getManagerCoreRequest.getAdvertiser_id());
        String date = Tools.getDatelaterDay(Tools.getCurrentDate("YYYY-MM-dd"), 1);//拿昨天的数据计算
        getBalanceRequest.setStart_date(date);
        getBalanceRequest.setEnd_date(date);
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineService.getManagerCore(getBalanceRequest));
    }

    @PostMapping("/canUseManage")
    @ApiOperation(value = "是否能使用管家", response = CanUseManage.class)
    public ResponseData canUseManage(@RequestBody CanUseManageRequest issetAccountRequest) {
        CanUseManage canUseManage = iOceanegineService.canUseManage(issetAccountRequest);
        if (canUseManage == null)
            return new ResponseData(ResponseData.Result.FAIL);
        return new ResponseData(ResponseData.Result.SUCCESS, canUseManage);
    }
}
